/**
 * JAVACC DEMO 1.0
 * @copy right dwusoft company All rights reserved. 
 * @Package com.apache.uct.service.plugins  
 */
package com.apache.uct.service.plugins;

import java.util.Date;

import com.apache.api.manager.PluginConnector;
import com.apache.api.vo.ParamsVo;
import com.apache.uct.common.entity.Act;
import com.apache.uct.common.entity.Sys;
import com.apache.uct.manager.ActGiveManager;
import com.apache.uct.manager.ActManager;
import com.apache.uct.manager.LockManager;

/**
 * description:  系统注册关联信息保存
 * @author dwusoft 创建时间：2015-3-24  
 * @Copyright(c)2014:北京--软件技术有限公司
 */
public class SysRelationSavePlugin implements PluginConnector {

	private ActManager actManager;
	private ActGiveManager actGiveManager;
	private LockManager lockManager;

	/**
	 * TODO 系统注册关联信息保存.  
	 */
	public Object execute(ParamsVo vo) throws Exception {
		String key = vo.getMethodKey();
		if ("saveInfo".equalsIgnoreCase(key)) {
			saveInfo(vo);
		} else if ("deleteInfo".equalsIgnoreCase(key)) {
			deleteInfo(vo);
		}
		return null;
	}

	private void saveInfo(ParamsVo vo) {
		Sys sys = (Sys) vo.getObj();
		Act act = new Act();
		act.setCreateUser(sys.getCreateUser());
		act.setSysEname(sys.getSysEname());
		act.setActCname(sys.getSysCname());
		act.setActEname(sys.getSysEname());
		act.setFullEname("/" + sys.getSysEname());
		act.setFullCname("/" + sys.getSysCname());
		act.setActStatus(1);
		act.setActType("menu");//默认菜单
		act.setFatherId("0");
		act.setCreateTime(new Date().getTime());
		ParamsVo<Act> actVo = new ParamsVo<Act>();
		actVo.setObj(act);
		actManager.saveInfo(actVo);
	}

	private void deleteInfo(ParamsVo vo) {
		Sys sys = (Sys) vo.getObj();
		ParamsVo pv = new ParamsVo();
		pv.setParams("sysEname", sys.getSysEname());
		pv.setParams("sysId", sys.getSysId());
		pv.setKey("BySysEname");
		//删除系统对应下所有权限
		//删除权限明细
		//删除资源 访问控制
		actManager.deleteInfo(pv);
		actGiveManager.deleteInfo(pv);
		lockManager.deleteInfo(pv);
	}

	public void setActManager(ActManager actManager) {
		this.actManager = actManager;
	}

	public void setActGiveManager(ActGiveManager actGiveManager) {
		this.actGiveManager = actGiveManager;
	}

	public void setLockManager(LockManager lockManager) {
		this.lockManager = lockManager;
	}

}
